//app.js
var httpUtils = require('./utils/httpUtils.js');
var utils = require('./utils/util.js');
var app = getApp();
App({
  onLaunch: function() {
    if (utils.isNull(wx.getStorageSync('userInfo')) || utils.isNull(wx.getStorageSync('userInfo').telephone)){
      wx.clearStorageSync();
    }
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    if ('test' == this.globalData.profile) {
      this.globalData.interfaceUrl = 'http://116.62.180.218:9027';
    } else if ('development' == this.globalData.profile) {
      this.globalData.interfaceUrl = 'http://localhost';
    } else if ('produce' == this.globalData.profile) {
      this.globalData.interfaceUrl = 'https://awwxlit.baiying365.com';
      this.globalData.uploadUrl = "https://baiying-order.oss-cn-hangzhou.aliyuncs.com";
      this.globalData.uploadPreUrl = "https://baiying-order.oss-cn-hangzhou.aliyuncs.com";
    }
    if (utils.isNull(wx.getStorageSync('loginSessionId'))) {
      // 登录
      wx.login({
        success: res => {
          // 发送 res.code 到后台换取 openId, sessionKey, unionId
          wx.request({
            url: this.globalData.interfaceUrl + '/sysUser/auth.do',
            data: {
              'bizParams': {
                'id': res.code
              }
            },
            success: function(res) {
              console.log('怪了' + res);
              wx.setStorageSync('loginSessionId', res.data.data.loginSessionId);
            },
            fail: function(res) {
              console.log(res);
              console.log('登陆失败');
            }
          })
        }
      })
    }

  },
  globalData: {
    userInfo: null,
    profile: 'test',
    interfaceUrl: '',
    uploadUrl: "https://by-test-hz.oss-cn-hangzhou.aliyuncs.com",
    uploadPreUrl: "https://by-test-hz.oss-cn-hangzhou.aliyuncs.com",
    downdLoadUrl:'https://a.app.qq.com/o/simple.jsp?pkgname=com.baiying365.antworker&fromcase=40003'
  }
})